﻿using System;
using System.Collections;
using System.Collections.Generic;
using System.Text;
using System.Xml;
using InfoJetSoft.Service.Entity;
using InfoJetSoft.Service.Util;
using System.Security.Cryptography;
using System.Security.Cryptography.Xml;
using System.Security.Principal;
using System.Security.Cryptography.X509Certificates;

//CID 0749 //2011.09.16 //Begin
namespace InfoJetSoft.Service.Worker
{
    class DigitalSignatureDeleteWorker
    {
        public static void deleteSignature(Form form)
        {
            string sigid = form.HttpContext.Request.Params["xdoc_param_dsig_sigid"];
            XmlElement signatureElement = DOMUtil.findNodeByJetId(form, sigid) as XmlElement;
            signatureElement.ParentNode.RemoveChild(signatureElement);
            foreach (SignedDataInfo signedDataInfo in form.SignedDataInfoList)
            {
                SignedElementInfo deletedSignedElementInfo = null;
                foreach (SignedElementInfo signedElementInfo in signedDataInfo.SignatureElementList)
                {
                    if (signedElementInfo.SignatureElement.Equals(signatureElement))
                    {
                        deletedSignedElementInfo = signedElementInfo;
                        break;
                    }
                }
                //CID 1521 //2013.01.01 //if break
                if (deletedSignedElementInfo != null)
                {
                    signedDataInfo.SignatureElementList.Remove(deletedSignedElementInfo);
                    if (signedDataInfo.Mode.Equals("single") && signedDataInfo.SignatureElementList.Count > 1)
                    {
                        signedDataInfo.HasExtraSignature = true;
                    }
                    else
                    {
                        signedDataInfo.HasExtraSignature = false;
                    }
                    break;
                }
            }
        }
    }
}
//CID 0749 //2011.09.16 //End